﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComUIControl
{
    public partial class TranslucentImageBox : UserControl
    {
        private Bitmap _image;
        public Bitmap Image
        {
            get
            {
                return _image;
            }
            set
            {
                if (_image != value)
                {
                    pictureBox1.Image = value;
                    _image = value;
                }
            }
        }
        public TranslucentImageBox()
        {
            this.Visible = false;
            InitializeComponent();
        }
        public delegate void ShowTitpImageDelegate(Bitmap img, Point p);
        public void ShowImage(Bitmap img, Point p)
        {
            if (this.InvokeRequired)
            {
                ShowTitpImageDelegate outdelegate = new ShowTitpImageDelegate(ShowImage);
                this.BeginInvoke(outdelegate, new object[] { img, p });
                return;
            }       
            this.Size = img.Size;
            this.Location = p;
            Image = img;
            this.Visible = true;
            pictureBox1.Invalidate();
        }

        public void RemainHidden()
        {
            if (this.InvokeRequired)
            {
                Action outdelegate = new Action(RemainHidden);
                this.BeginInvoke(outdelegate, new object[] { });
                return;
            }
            this.Visible = false;
            Image = null;
        }
    }
}
